package com.innovations.inn.service.impl;

import java.util.List;
import com.innovations.common.utils.DateUtils;
import com.innovations.common.utils.uuid.IdGeneratorSnowflake;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.innovations.inn.mapper.EnterpriseQualificationMapper;
import com.innovations.inn.domain.EnterpriseQualification;
import com.innovations.inn.service.IEnterpriseQualificationService;

/**
 * 企业资质Service业务层处理
 * 
 * @author dp
 * @date 2024-08-09
 */
@Service
public class EnterpriseQualificationServiceImpl implements IEnterpriseQualificationService 
{
    @Autowired
    private EnterpriseQualificationMapper enterpriseQualificationMapper;
    @Autowired
    IdGeneratorSnowflake idGeneratorSnowflake;

    /**
     * 查询企业资质
     * 
     * @param enterpriseQualificationId 企业资质主键
     * @return 企业资质
     */
    @Override
    public EnterpriseQualification selectEnterpriseQualificationByEnterpriseQualificationId(Long enterpriseQualificationId)
    {
        return enterpriseQualificationMapper.selectEnterpriseQualificationByEnterpriseQualificationId(enterpriseQualificationId);
    }

    /**
     * 查询企业资质列表
     * 
     * @param enterpriseQualification 企业资质
     * @return 企业资质
     */
    @Override
    public List<EnterpriseQualification> selectEnterpriseQualificationList(EnterpriseQualification enterpriseQualification)
    {
        return enterpriseQualificationMapper.selectEnterpriseQualificationList(enterpriseQualification);
    }

    /**
     * 新增企业资质
     * 
     * @param enterpriseQualification 企业资质
     * @return 结果
     */
    @Override
    public int insertEnterpriseQualification(EnterpriseQualification enterpriseQualification)
    {
        enterpriseQualification.setCreateTime(DateUtils.getNowDate());
        return enterpriseQualificationMapper.insertEnterpriseQualification(enterpriseQualification);
    }

    /**
     * 修改企业资质
     * 
     * @param enterpriseQualification 企业资质
     * @return 结果
     */
    @Override
    public int updateEnterpriseQualification(EnterpriseQualification enterpriseQualification)
    {
        return enterpriseQualificationMapper.updateEnterpriseQualification(enterpriseQualification);
    }

    /**
     * 批量删除企业资质
     * 
     * @param enterpriseQualificationIds 需要删除的企业资质主键
     * @return 结果
     */
    @Override
    public int deleteEnterpriseQualificationByEnterpriseQualificationIds(Long[] enterpriseQualificationIds)
    {
        return enterpriseQualificationMapper.deleteEnterpriseQualificationByEnterpriseQualificationIds(enterpriseQualificationIds);
    }

    /**
     * 删除企业资质信息
     * 
     * @param enterpriseQualificationId 企业资质主键
     * @return 结果
     */
    @Override
    public int deleteEnterpriseQualificationByEnterpriseQualificationId(Long enterpriseQualificationId)
    {
        return enterpriseQualificationMapper.deleteEnterpriseQualificationByEnterpriseQualificationId(enterpriseQualificationId);
    }

    /**
     * 实体数据补全
     *
     * @param enterpriseQualification 实体
     * @param userId       用户id
     * @param crateType    创建类型 1：新增 2：修改
     */
    @Override
    public void completeData(EnterpriseQualification enterpriseQualification, Long userId, Integer crateType) {
        //主键
        if (enterpriseQualification.getEnterpriseQualificationId() == null || "".equals(enterpriseQualification.getEnterpriseQualificationId())) {
            enterpriseQualification.setEnterpriseQualificationId(idGeneratorSnowflake.nextId());
        }
        //创建人、创建时间
        if (crateType == 1) {
            if (enterpriseQualification.getCreateBy() == null || "".equals(enterpriseQualification.getCreateBy())) {
                enterpriseQualification.setCreateBy(userId);
            }
            if (enterpriseQualification.getCreateTime() == null) {
                enterpriseQualification.setCreateTime(DateUtils.getNowDate());
            }
        }
        //修改人
        if (enterpriseQualification.getModifyBy() == null) {
            enterpriseQualification.setModifyBy(userId);
        }
        //修改时间
        if (enterpriseQualification.getModifyTime() == null) {
            enterpriseQualification.setModifyTime(DateUtils.getNowDate());
        }
    }
}
